import numpy as np

# numpy
# https://numpy.org/doc/stable/user/quickstart.html

# basis
a = np.arange(15).reshape(3, 5)
print(a)
print(a.shape)  #
print(a.ndim)  #
print(a.dtype.name)
print(a.itemsize)
print(a.size)  #
print(type(a))
print('*' * 10)
b = np.array([6, 7, 8])
print(b)
print(type(b))
print('*' * 10)

# array creation
a = np.array([2, 3, 4])
print(a)
print(a.dtype)
print('*' * 10)
b = np.array([1.2, 3.5, 5.1])
print(b.dtype)
print('*' * 10)
c = np.array([[1, 2], [3, 4]], dtype=complex)
print(c)
print('*' * 10)

print(np.zeros((3, 4)))
print(np.ones((2, 3, 4), dtype=np.int16))
print('*' * 10)

# import sys
# np.set_printoptions(threshold=sys.maxsize)

# array operations
a = np.array([20, 30, 40, 50])
b = np.arange(4)
print(a)
print(b)
c = a - b
print(c)
print(b ** 2)
print(10 * np.sin(a))
print(a < 35)
print('*' * 10)

A = np.array([[1, 1], [0, 1]])
B = np.array([[2, 0], [3, 4]])
print(A)
print(B)
print(A * B)  # elementwise product
print(A @ B)  # matrix product
print(A.dot(B))  # matrix product
print('*' * 10)

B = np.arange(3)
print(B)
print(np.exp(B))
print(np.sqrt(B))
print('*' * 10)

# indexing
a = np.arange(10) ** 3
print(a)
print(a[2])
print(a[2:5])
print(a[::-1])
print('*' * 10)

c = np.array([[[0, 1, 2], [10, 12, 13]], [[100, 101, 102], [110, 112, 113]]])
print(c.shape)
print(c[1, ...])  # same as c[1, :, :] or c[1]
print(c[..., 2])  # same as c[:, :, 2]
